<template>
    <div>
        <Header></Header>
        <Sidebar></Sidebar>
        <div class="content-box" :class="{'content-collapse':collapse}">
            <tags></tags>
            <div class="content">
                <transition name="move" mode="out-in">
                    <!-- include的参数是组件中的name属性值 -->
                    <keep-alive include="Dashboard">
                        <router-view></router-view>
                    </keep-alive>
                </transition>
                <el-backtop target=".content"></el-backtop>
            </div>
        </div>
    </div>
</template>

<script>
    import Header from './Header'
    import Sidebar from './Sidebar'
    import Tags from './Tags'

    import bus from 'utils/bus.js'
    import getLocation from 'utils/positionLocation.js'
    export default {
        name: 'Home',
        components: {
            Header,
            Sidebar,
            Tags
        },
        data () {
            return {
                collapse: false,
                tagsList: [],
            }
        },
        created () {
            // 需要判断是否有token，如果没有应该跳转登录页面

            // 根据sidebar是否展开来设置content的样式
            bus.$on('collapse-content', msg => {
                this.collapse = msg;
            });


            // 只有在标签列表的页面菜使用keep-alive，关闭后不需要保存在内存
            bus.$on('tags', msg => {
                let arr = [];
                for (let i = 0, len = msg.length; i < len; i++) {
                    msg[i].name && arr.push(msg[i].name.charAt(0).toUpperCase() + msg[i].name.slice(1));
                }
                this.tagsList = arr;
            });

            // 获取用户地理位置
            const _this = this;
            getLocation(_this)
        }
    }
</script>
<!-- home中的样式写到main.css中了 -->